# # 函数
# # 函数体
# def calc_sum(beg, end):
#     sum = 0
#     for i in range(beg, end + 1):
#         sum += i
#     return sum
#
#
# # 求1~100的和
# print(calc_sum(1, 100))
# # 求1~1000的和
# print(calc_sum(1, 1000))
# # 求1~10000的和
# print(calc_sum(1, 10000))

# # 半缺省函数
# def test(a, b = 20, c = 30):
#     print(a, b, c)
#
#
# test(10)
# test('hello')
# test(True)

# def add(x, y):
#     return x + y
#
#
# print(add(10, 20))
# print(add(1.5, 2.6))
# print(add('hello', 'world'))

# # 求 beg 到 end 的乘积
# def calc_sum(beg, end):
#     sum = 1
#     for i in range(beg, end + 1):
#         i += 1
#         sum *= i
#     return sum
#
#
# result = calc_sum(10, 20)
# print(result)

# # 判断一个数是否是奇数
# def isOdd(num):
#     """
#     用来判定 num 是不是奇数！ 如果是奇数返回 True, 不是返回 False
#     :param num: 要判定的整数
#     :return: 返回 True False 表示是不是奇数
#     """
#     if num % 2 == 0:
#         return False
#     return True
#
#
# print(isOdd(10))
# print(isOdd(19))

# # 写一个函数，返回平面上的一个点
# # 横坐标，纵坐标
# def getPoint():
#     x = 10
#     y = 20
#     return x, y
#
#
# a, b = getPoint()
# print(a, b)
# _, b = getPoint()
# print(b)

# # 局部变量和全局变量
# x = 10
#
#
# def test():
#     global x
#     x = 20
#     print(f"函数内部: {x}")
#
#
# test()
# print(f'函数外部：{x}')

# def test():
#     print('执行函数体代码')
#     print('执行函数体代码')
#     print('执行函数体代码')
#
#
# print('1111')
# test()
# print('2222')
# test()
# print('3333')
# test()

# def isOdd(num):
#     if num % 2 == 0:
#         return False
#     return True
#
#
# print(isOdd(10))

# def a():
#     num1 = 10
#     print('函数a()')
#
#
# def b():
#     num2 = 20
#     a()
#     print('函数b()')
#
#
# def c():
#     num3 = 30
#     b()
#     print('函数c()')
#
#
# def d():
#     num4 = 40
#     c()
#     print('函数d()')
#
#
# d()

# # 递归
# # 写一个函数求 n!
# def factor(n):
#     if n == 1:
#         return 1
#     return n * factor(n - 1)
#
#
# number = input('请输入一个数：')
# number = int(number)
# print(factor(number))

# def add(x, y, debug=False):
#     if debug:
#         print(f'x = {x}, y = {y}')
#     return x + y
#
#
# result = add(10, 20)
# print(result)

# def test(x, y):
#     print(f'x = {x}')
#     print(f'y = {y}')
#
#
# test(x=10, y=20)
# test(10, 20)
